﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuantitativeInvestment.Bean;
using QuantitativeInvestment.Factor;
using System.Data;
using System.Reflection;
namespace QuantitativeInvestment.CharacterAnalyzer
{
    class CharacterAnalyzer
    {
        public string name;
        public List<Factor.Factor> factorList;
        public Container.Container container;
        public CharacterAnalyzer()
        {
            this.factorList = new List<Factor.Factor>();
        }

        //输入已经选择股票组合 和备选股票组合（可选）
        public virtual void analyse(PortfolioManager portfolioManager)
        {

        }
        public virtual void analyse(Portfolio p, Portfolio stockPoolPortfolio = null)
        {

        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static CharacterAnalyzer createContainerByName(String name)
        {
            CharacterAnalyzer analyzer = null;
            DataSet ds = new DataSet();
            ds.ReadXml(System.Windows.Forms.Application.StartupPath + "/Config" + "Characters.xml");
            DataRow[] rows = ds.Tables["character"].Select("name='" + name + "'");
            if (rows.Length > 0)
            {
                Assembly a = Assembly.GetExecutingAssembly();
                analyzer = (CharacterAnalyzer)a.CreateInstance(rows[0]["objectName"].ToString());
            }

            return analyzer;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static List<string> getAnalyzerList()
        {
            DataSet ds = new DataSet();
            ds.ReadXml(System.Windows.Forms.Application.StartupPath + "/Config" + "Characters.xml");
            List<string> modelNameList = new List<string>();
            foreach (DataRow row in ds.Tables["character"].Rows)
            {
                modelNameList.Add(row["name"].ToString());
            }

            return modelNameList;
        }
        

    }
}
